package com.farsunset.cim.sdk.server.slc.handler;

import io.netty.channel.ChannelHandler;

import java.util.LinkedHashMap;

/**
 * @author slc
 * @date 2025/6/6
 **/
public abstract class SlcAcceptorBuilder<T> {
    private boolean loadDeHandler = true;
    private boolean usePlatformOptimization;
    private final LinkedHashMap<String, ChannelHandler> appChannelHandlerMapByDeBefore = new LinkedHashMap<>();
    private final LinkedHashMap<String, ChannelHandler> appChannelHandlerMapByDeAfter = new LinkedHashMap<>();
    private final LinkedHashMap<String, ChannelHandler> webChannelHandlerMapByDeBefore = new LinkedHashMap<>();
    private final LinkedHashMap<String, ChannelHandler> webChannelHandlerMapByDeAfter = new LinkedHashMap<>();

    public SlcAcceptorBuilder<T> setLoadDeHandler(boolean loadDeHandler) {
        this.loadDeHandler = loadDeHandler;
        return this;
    }

    public SlcAcceptorBuilder<T> setUsePlatformOptimization(boolean usePlatformOptimization) {
        this.usePlatformOptimization = usePlatformOptimization;
        return this;
    }

    public SlcAcceptorBuilder<T> setAppChannelHandlerMapByDeBefore(LinkedHashMap<String, ChannelHandler> appChannelHandlerMapByDeBefore) {
        this.appChannelHandlerMapByDeBefore.clear();
        this.appChannelHandlerMapByDeBefore.putAll(appChannelHandlerMapByDeBefore);
        return this;
    }

    public SlcAcceptorBuilder<T> addAppChannelHandlerByDeBefore(String key, ChannelHandler channelHandler) {
        this.appChannelHandlerMapByDeBefore.put(key, channelHandler);
        return this;
    }

    public SlcAcceptorBuilder<T> setAppChannelHandlerMapByDeAfter(LinkedHashMap<String, ChannelHandler> appChannelHandlerMapByDeAfter) {
        this.appChannelHandlerMapByDeAfter.clear();
        this.appChannelHandlerMapByDeAfter.putAll(appChannelHandlerMapByDeAfter);
        return this;
    }

    public SlcAcceptorBuilder<T> addAppChannelHandlerByDeAfter(String key, ChannelHandler channelHandler) {
        this.appChannelHandlerMapByDeAfter.put(key, channelHandler);
        return this;
    }


    public SlcAcceptorBuilder<T> setWebChannelHandlerMapByDeAfter(LinkedHashMap<String, ChannelHandler> webChannelHandlerMapByDeAfter) {
        this.webChannelHandlerMapByDeAfter.clear();
        this.webChannelHandlerMapByDeAfter.putAll(webChannelHandlerMapByDeAfter);
        return this;
    }

    public SlcAcceptorBuilder<T> addWebChannelHandlerByDeAfter(String key, ChannelHandler channelHandler) {
        this.webChannelHandlerMapByDeAfter.put(key, channelHandler);
        return this;
    }

    public SlcAcceptorBuilder<T> setWebChannelHandlerMapByDeBefore(LinkedHashMap<String, ChannelHandler> webChannelHandlerMapByDeBefore) {
        this.webChannelHandlerMapByDeBefore.clear();
        this.webChannelHandlerMapByDeBefore.putAll(webChannelHandlerMapByDeBefore);
        return this;
    }

    public SlcAcceptorBuilder<T> addWebChannelHandlerByDeBefore(String key, ChannelHandler channelHandler) {
        this.webChannelHandlerMapByDeBefore.put(key, channelHandler);
        return this;
    }

    public boolean isLoadDeHandler() {
        return loadDeHandler;
    }

    public boolean isUsePlatformOptimization() {
        return usePlatformOptimization;
    }

    public LinkedHashMap<String, ChannelHandler> getAppChannelHandlerMapByDeBefore() {
        return appChannelHandlerMapByDeBefore;
    }

    public LinkedHashMap<String, ChannelHandler> getAppChannelHandlerMapByDeAfter() {
        return appChannelHandlerMapByDeAfter;
    }

    public LinkedHashMap<String, ChannelHandler> getWebChannelHandlerMapByDeBefore() {
        return webChannelHandlerMapByDeBefore;
    }

    public LinkedHashMap<String, ChannelHandler> getWebChannelHandlerMapByDeAfter() {
        return webChannelHandlerMapByDeAfter;
    }

    public abstract T build();

}
